require 'statistic/fields_counter'
require 'html/xmltree'

module Statistic
  
  class HTMLFieldsCounter < FieldsCounter
    
    public
    
    def initialize( crawl_table, conditions = "status = 200" )
      super crawl_table, conditions
      @parser = HTMLTree::XMLParser.new false, true
    end
    
    protected
    
    def analyse(c)
      begin
        @parser.reset
        @parser.feed c.body
      rescue REXML::ParseException => e
        # continue with a partial prased document
        if @parser.document.root.nil? then
          @records_analyzed_fail << [c, "#{e.to_s}\n#{e.backtrace.join("\n")}"]
          return
        end
      end
      
      analyse_html(@parser.document)
    end
    
    
    def analyse_html(xml_tree)
      
    end
    
  end
  
end